﻿var ReportConfig=new Object();

ReportConfig.connecteState=0;
ReportConfig.interId=-1;
ReportConfig.MNGServerURL="";
ReportConfig.serverURL="";
ReportConfig.reportLoopTime=0;
ReportConfig.ns;

function ReportStartRun(){
	ReportConfig.interId=setInterval(StartConnectServer,ReportConfig.reportLoopTime*1000,this);
}
function ReportStopRun(){
	clearInterval(ReportConfig.interId);
}
function StartConnectServer(root){
	
	if(root.ReportConfig.connecteState==0){
		if(root.ReportConfig.MNGServerURL==undefined){
			trace("ManagerServerURL NOT set!");
			root.ReportStopRun();
			return;
		}else{
			root.initNetConnect();
			root.ReportConfig.connecteState=1;
		}
	}
	else if(root.ReportConfig.connecteState==2){
		//trace("report"+root.chatGroupCount);
		ReportConfig.ns.call("report",null,{loading:root.chatGroupCount});
	}
}

function NSStatus(info){
	if(info.level=="status"){
		switch(info.code){
			case "NetConnection.Connect.Success":
				trace("connect Manager Server Success!");
				ReportConfig.connecteState=2;
			break;
			
			case "NetConnection.Connect.Closed":
				trace("Manager Server closed!");
				ReportConfig.connecteState=0;
			break;
			
			default:
				MyTrace(info);
			break;	
		}
	}
	else if(info.level=="error"){
		trace("ERROR INFO:"+info.code+"|"+info.description);
	}
}

function initNetConnect(){
	ReportConfig.ns=new NetConnection();
	ReportConfig.ns.onStatus = NSStatus;
	trace("connect to:"+ReportConfig.MNGServerURL);
	ReportConfig.ns.connect(ReportConfig.MNGServerURL,"CS",ReportConfig.serverURL);
}